const express = require('express');
const favicon = require('serve-favicon');
const session = require('express-session');

const loginRouter=require('./router/loginRouter');
const registerRouter=require('./router/registerRouter')
const findoutRouter=require('./router/findoutRouter');
const wanshanjianliziliaoRouter=require('./router/wanshanjianliziliaoRouter');
const wanshanqiyeziliaoRouter=require('./router/wanshanqiyeziliaoRouter');
const zhiweiRouter =require('./router/zhiweiRouter');
const jianlizhongxinRouter=require('./router/jianlizhongxinRouter');
const zhiweiguanliRouter=require('./router/zhiweiguanliRouter');
const chuangjianjianliRouter=require('./router/chuangjianjianliRouter');
const fabuzhiweiRouter=require('./router/fabuzhiweiRouter');
const zhaogongzuoRouter=require('./router/zhaogongzuoRouter');


const server = express();

server.use(favicon(__dirname + '/public/images/logo.ico'));
server.use(express.static(__dirname + '/public'));
server.use(express.json());
server.use(express.urlencoded({ extended: true }));
server.use(session({
  name: 'demo',
  secret: 'web281',
  cookie: {
    maxAge: 1000 * 5
  },
  rolling: true,
  resave: true
}));



server.use(loginRouter);
server.use(registerRouter);
server.use(findoutRouter);
server.all('*', function (req, res, next) {
  if (req.session.userSession) {
    next();
  } else {
    res.send({ code: 302, msg: '没有登录，请重新登录' });
  }
})
server.use(wanshanjianliziliaoRouter);
server.use(wanshanqiyeziliaoRouter);
server.use(zhiweiRouter);
server.use(jianlizhongxinRouter);
server.use(zhiweiguanliRouter);
server.use(chuangjianjianliRouter);
server.use(fabuzhiweiRouter);
server.use(zhaogongzuoRouter);

server.listen(8080, function () {
  console.log('项目启动了')
});
